package com.itlong.cloud.commons.service.impl;

import com.itlong.cloud.POJO.DTO.operate.OperateLoggerDeveloperLogGetPageDTO;
import com.itlong.cloud.POJO.VO.operate.OperateDeveloperLogVO;
import com.itlong.cloud.commons.dao.IDeveloperLogDao;
import com.itlong.cloud.commons.service.IDeveloperLogService;
import com.itlong.cloud.utils.data.handler.SqlUtil;
import com.itlong.cloud.utils.page.Page;
import com.itlong.cloud.utils.words.StringHandlerUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.Map;

/**
 * <desc>
 *      开发者日志业务处理实现类
 * </desc>
 *
 * @createDate 2018/12/18
 */
@Service
public class DeveloperLogServiceImpl implements IDeveloperLogService {

    @Autowired
    IDeveloperLogDao iDeveloperLogDao;

    /**
     * <desc>
     *      获取分页数据
     * </desc>
     *
     * @param pageDTO 查询参数DTO
     * @return page模型
     * @author Qiang.S
     * @createDate 2018/12/18
     */
    @Override
    public Page<OperateDeveloperLogVO> getDeveloperLogByPage(OperateLoggerDeveloperLogGetPageDTO pageDTO) throws Exception {
        //将DTO转换为Map params
        Map<String, Object> params = SqlUtil.convertBeanToMapParams(pageDTO);
        //分页类默认pageSize为20
        Page<OperateDeveloperLogVO> page = new Page<>();
        page.getPage().setPageSize(pageDTO.getPageSize());
        page.getPage().setCurrentPage(pageDTO.getCurrentPage());
        params.put("currentPage", page.getPage().getStartSlip());
        params.put("pageSize", page.getPage().getPageSize());
        //填充返回数据集
        page.setRows(iDeveloperLogDao.getPage(params), iDeveloperLogDao.getPageCount(params));
        return page;
    }

    /**
     * <desc>
     *      删除功能
     * </desc>
     *
     * @param logIds 开发者日志id数组
     * @return sql执行行数
     * @author Qiang.S
     * @createDate 2018/12/18
     */
    @Override
    @Transactional(rollbackFor = Exception.class,propagation = Propagation.REQUIRED)
    public Integer delete(String logIds){
        return iDeveloperLogDao.delete(StringHandlerUtil.splitString(logIds));
    }
}
